@(currentPage: com.avaje.ebean.Page[Question], currentSortBy: String, currentOrder: String, currentFilter: String)
@header()

@link(newPage:Int, newSortBy:String) = @{
    
    var sortBy = currentSortBy
    var order = currentOrder
    
    if(newSortBy != null) {
        sortBy = newSortBy
        if(currentSortBy == newSortBy) {
            if(currentOrder == "asc") {
                order = "desc"
            } else {
                order = "asc"
            }
        } else {
            order = "asc"
        }
    }
    
    // Generate the link
    routes.AdminQuestion.listQuestion(newPage, sortBy, order, currentFilter)
    
}

@headerview(key:String, title:String) = {
    <th class="@key.replace(".","_") headerview @if(currentSortBy == key) @{if(currentOrder == "asc") "headerviewSortDown" else "headerviewSortUp"}">
        <a href="@link(0, key)">@title</a>
    </th>
}

@main("") {

	<div class="bs-docs-example" >
    	
    	<div class="bs-docs-example-after" >
    	Administration
    	</div>
     
     	<legend> Contenu de la table Question </legend>
    	<br>



    @if(flash.containsKey("success")) {
        <div class="alert-message warning">
            <strong>Done!</strong> @flash.get("success")
        </div>
    } 


    @if(currentPage.getTotalRowCount == 0) {
        
        <div class="well">
            <em>Nothing to display</em>
        </div>
        
    } else {
        
        <table class="table table-striped">
  <thead>
                <tr>
                	@headerview("idQuestion", "id du question")
                    @headerview("libelleQuestion", "Libelle")
                    @headerview("commentaire", "Commentaire")
                    @headerview("chapitre_id_chapitre", "chapitre de la question")
                    @headerview("niveau_question_id_niveau_q", "niveau de la question")
                </tr>
            </thead>
            <tbody>

                @for(question <- currentPage.getList) {
                    <tr>
                    	<td>
                        	<a href="@routes.AdminQuestion.editQuestion(question.getIdQuestion)">@question.getIdQuestion </a>
                        </td>
                        <td>
                        	<a href="@routes.AdminQuestion.editQuestion(question.getIdQuestion)">@question.getLibelleQuestion </a>
                        </td>
                        <td>
                        	<a href="@routes.AdminQuestion.editQuestion(question.getIdQuestion)">@question.getCommentaire </a>
                        </td>
                        <td>
                            @if(question.getChapitre == null) {
                                <em>-</em>
                            } else {
                                @question.getChapitre.getLibelleC()
                            }
                        </td>
                        <td>
                            @if(question.getNiveauQuestion == null) {
                                <em>-</em>
                            } else {
                                @question.getNiveauQuestion.getLibelleNiveau()
                            }
                        </td>                        
                    </tr>
                }
				
            </tbody>
            
        </table>

        <div id="actions">   
        
		<a class="btn success" id="add" href="@routes.Application.consoleAdmin()">Retour</a>    
        <a class="btn success" id="add" href="@routes.AdminQuestion.createQuestion()">Ajouter un question</a>    
   		 </div>

    
        </div>
       


    
        <div id="pagination" class="pagination">
            <ul>
                @if(currentPage.hasPrev) {
                    <li class="prev">
                        <a href="@link(currentPage.getPageIndex - 1, null)">&larr; Previous</a>
                    </li>
                } else {
                    <li class="prev disabled">
                        <a>&larr; Previous</a>
                    </li>
                }
                <li class="current">
                    <a>Displaying @currentPage.getDisplayXtoYofZ(" to "," of ")</a>
                </li>
                @if(currentPage.hasNext) {
                    <li class="next">
                        <a href="@link(currentPage.getPageIndex + 1, null)">Next &rarr;</a>
                    </li>
                } else {
                    <li class="next disabled">
                        <a>Next &rarr;</a>
                    </li>
                }
            </ul>
        </div>
        
    }
        
}

            